/*
* ECARX Technology Limited is the owner of the copyright and the trade secret of this software.
* Without permission, no one has the right to obtain, disclose or use this software in any way.
*/

package ecarx.xsf.notificationcenter.scenecard;


import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

import java.util.List;

import ecarx.xsf.notificationcenter.common.Constants;

public class ISceneCardInfoV2 implements Parcelable, Comparable<ISceneCardInfoV2> {

    /**
     * 数据封装 bundle
     */
    private final Bundle bundle;

    /**
     * 按钮点击事件
     */
    private List<IPendingIntentAction> actions;

    /**
     * 可见即可说事件
     */
    private List<IPendingIntentAction> seeSayActions;

    /**
     * 场景卡片
     */
    private List<IPendingIntentAction> smartCardActions;

    /**
     * 消息key
     */
    private final String key;

    public ISceneCardInfoV2(int id, String pkgname, boolean beep, boolean tts, boolean seeSay, String title, String subtitle, String backgroud, String detailImg, String tag, long when, List<IPendingIntentAction> actions, List<IPendingIntentAction> seeSayActions, List<IPendingIntentAction> smartCardActions) {
        bundle = new Bundle();
        bundle.putInt(Constants.ISceneCardInfoKey.KEY_ID, id);
        bundle.putString(Constants.ISceneCardInfoKey.KEY_PACKAGE_NAME, pkgname);
        bundle.putBoolean(Constants.ISceneCardInfoKey.KEY_BEEP, beep);
        bundle.putBoolean(Constants.ISceneCardInfoKey.KEY_TTS, tts);
        bundle.putBoolean(Constants.ISceneCardInfoKey.KEY_SEE_SAY, seeSay);
        bundle.putString(Constants.ISceneCardInfoKey.KEY_TITLE, title);
        bundle.putString(Constants.ISceneCardInfoKey.KEY_SUB_TITLE, subtitle);
        bundle.putString(Constants.ISceneCardInfoKey.KEY_BACKGROUND, backgroud);
        bundle.putString(Constants.ISceneCardInfoKey.KEY_DETAIL_IMG, detailImg);
        bundle.putString(Constants.ISceneCardInfoKey.KEY_TAG, tag);
        bundle.putLong(Constants.ISceneCardInfoKey.KEY_WHEN,when);
        this.actions = actions;
        this.seeSayActions = seeSayActions;
        this.smartCardActions = smartCardActions;
        this.key = key();
    }

    protected ISceneCardInfoV2(Parcel in) {
        bundle = in.readBundle(getClass().getClassLoader());
        actions = in.createTypedArrayList(IPendingIntentAction.CREATOR);
        seeSayActions = in.createTypedArrayList(IPendingIntentAction.CREATOR);
        smartCardActions = in.createTypedArrayList(IPendingIntentAction.CREATOR);
        key = in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeBundle(bundle);
        dest.writeTypedList(actions);
        dest.writeTypedList(seeSayActions);
        dest.writeTypedList(smartCardActions);
        dest.writeString(key);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<ISceneCardInfoV2> CREATOR = new Creator<ISceneCardInfoV2>() {
        @Override
        public ISceneCardInfoV2 createFromParcel(Parcel in) {
            return new ISceneCardInfoV2(in);
        }

        @Override
        public ISceneCardInfoV2[] newArray(int size) {
            return new ISceneCardInfoV2[size];
        }
    };


    public void setSmartCardActions(List<IPendingIntentAction> smartCardActions) {
        this.smartCardActions = smartCardActions;
    }

    public List<IPendingIntentAction> getSmartCardActions() {
        return smartCardActions;
    }



    private String key() {
        return bundle.getInt(Constants.ISceneCardInfoKey.KEY_ID) + "|" + bundle.getString(Constants.ISceneCardInfoKey.KEY_PACKAGE_NAME) + "|" + bundle.getString(Constants.ISceneCardInfoKey.KEY_TAG);
    }

    public int getId() {
        return bundle.getInt(Constants.ISceneCardInfoKey.KEY_ID);
    }


    public String getPkgname() {
        return bundle.getString(Constants.ISceneCardInfoKey.KEY_PACKAGE_NAME);
    }


    public boolean isBeep() {
        return bundle.getBoolean(Constants.ISceneCardInfoKey.KEY_BEEP);
    }

    public boolean isTts() {
        return  bundle.getBoolean(Constants.ISceneCardInfoKey.KEY_TTS);
    }

    public String getTitle() {
        return bundle.getString(Constants.ISceneCardInfoKey.KEY_TITLE);
    }


    public String getTag() {
        return bundle.getString(Constants.ISceneCardInfoKey.KEY_TAG);
    }


    public long getWhen() {
        return bundle.getLong(Constants.ISceneCardInfoKey.KEY_WHEN);
    }


    public List<IPendingIntentAction> getActions() {
        return actions;
    }

    public void setActions(List<IPendingIntentAction> actions) {
        this.actions = actions;
    }

    public List<IPendingIntentAction> getSeeSayActions() {
        return seeSayActions;
    }

    public String getKey() {
        return key;
    }


    public boolean isSeeSay() {
        return bundle.getBoolean(Constants.ISceneCardInfoKey.KEY_SEE_SAY);
    }

    public void setSeeSayActions(List<IPendingIntentAction> seeSayActions) {
        this.seeSayActions = seeSayActions;
    }

    public String getBackground() {
        return bundle.getString(Constants.ISceneCardInfoKey.KEY_BACKGROUND);
    }

    public String getSubtitle() {
        return bundle.getString(Constants.ISceneCardInfoKey.KEY_SUB_TITLE);
    }

    public String getDetailImg() {
        return bundle.getString(Constants.ISceneCardInfoKey.KEY_DETAIL_IMG);
    }


    @Override
    public int compareTo(@NonNull ISceneCardInfoV2 o) {
        if (getWhen() < o.getWhen()) {
            return 1;
        } else if (getWhen() > o.getWhen()) {
            return -1;
        }
        return 0;
    }

    @Override
    public String toString() {
        return "ISceneCardInfo{" +
                "id=" + getId() +
                ", pkgname='" + getPkgname() + '\'' +
                ", beep=" + isBeep() +
                ", tts=" + isTts() +
                ", seeSay=" + isSeeSay() +
                ", title='" + getTitle() + '\'' +
                ", subtitle='" + getSubtitle() + '\'' +
                ", background='" + getBackground() + '\'' +
                ", detailImg='" + getDetailImg() + '\'' +
                ", tag='" + getTag() + '\'' +
                ", when=" + getWhen() +
                ", actions=" + actions +
                ", seeSayActions=" + seeSayActions +
                ", smartCardActions=" + smartCardActions +
                ", key='" + key + '\'' +
                '}';
    }
}
